home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 22 / CU Amiga Magazine's Super CD-ROM 22 (1998)(EMAP Images)(GB)[!][issue 1998-05].iso / PowerPC / System / PPCReleaseDEV / Examples / Msg3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-21  |  5.7 KB  |  191 lines

  1. /* This test program sends 1000 messages to the PPC and
  2.    shows how long this takes.
  3.    The Messages are send synchron and every msg must
  4.    be replied after another.
  5.    Each Message has the Body "Text sent by M68k processor\n"
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <exec/nodes.h>
  10. #include <exec/lists.h>
  11. #include <exec/memory.h>
  12. #include <utility/tagitem.h>
  13. #include <powerup/ppclib/interface.h>
  14. #include <powerup/ppclib/message.h>
  15. #include <powerup/ppclib/tasks.h>
  16. #include <powerup/proto/ppc.h>
  17. #include <proto/exec.h>
  18. #include <proto/dos.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include "time.h"
  22. #include "time_protos.h"
  23.  
  24. #define TEXT            "Text sent by M68k processor\n"
  25. #define    MSGCOUNT    1000
  26.  
  27. struct StartupData
  28. {
  29.     ULONG    MsgCount;
  30. };
  31.  
  32. extern struct Library    *SysBase;
  33.  
  34. int    main(void)
  35. {
  36. struct Library        *PPCLibBase;
  37. struct TagItem        MyTags[10];
  38. void            *PPCPort;
  39. void            *ReplyPort;
  40. void            *StartupMsg;
  41. void            *M68kMsg;
  42. void            *PPCMsg;
  43. void            *ElfObject;
  44. void            *Task;
  45. UBYTE            *Body;
  46. struct StartupData    *StartupData;
  47. void            *MyTimerObject;
  48. ULONG            i;
  49.  
  50.   printf("Opening ppc.library\n");
  51.   if (PPCLibBase = OpenLibrary("ppc.library", 44))
  52.   {
  53.     if (MyTimerObject=TimerCreateObject())
  54.     {
  55.       printf("Loading PPC object\n");
  56.       if (ElfObject=PPCLoadObject("PROGDIR:Msg3PPC.elf"))
  57.       {
  58.         printf("Creating reply port\n");
  59.         MyTags[0].ti_Tag    =    TAG_DONE;
  60.         if (ReplyPort = PPCCreatePort(MyTags))
  61.         {
  62.           if (StartupMsg = PPCCreateMessage(ReplyPort, 0))
  63.           {
  64.             printf("Allocating StartupData\n");
  65.             if (StartupData = PPCAllocVec(sizeof(struct StartupData), MEMF_ANY))
  66.             {
  67.               StartupData->MsgCount    =    MSGCOUNT;
  68.  
  69.               printf("Creating PPC task\n");
  70.               MyTags[0].ti_Tag    =    PPCTASKTAG_STARTUP_MSG;
  71.               MyTags[0].ti_Data    =(ULONG) StartupMsg;
  72.  
  73.               MyTags[1].ti_Tag    =    PPCTASKTAG_STARTUP_MSGDATA;
  74.               MyTags[1].ti_Data    =(ULONG) StartupData;
  75.  
  76.               MyTags[2].ti_Tag    =    PPCTASKTAG_STARTUP_MSGLENGTH;
  77.               MyTags[2].ti_Data    =    0;
  78.  
  79.               MyTags[3].ti_Tag    =    PPCTASKTAG_STARTUP_MSGID;
  80.               MyTags[3].ti_Data    =    0;
  81.  
  82.               MyTags[4].ti_Tag    =    PPCTASKTAG_MSGPORT;
  83.               MyTags[4].ti_Data    =    TRUE;
  84.  
  85.               MyTags[5].ti_Tag    =    TAG_DONE;
  86.  
  87.               if (Task = PPCCreateTask(ElfObject, MyTags))
  88.               {
  89.                 if (PPCPort=(void*) PPCGetTaskAttrsTags(Task,
  90.                                                         PPCTASKINFOTAG_MSGPORT,0,
  91.                                                         TAG_END))
  92.                 {
  93.                   printf("Allocating memory for message body\n");
  94.                   if (Body = PPCAllocVec(sizeof(TEXT), MEMF_PUBLIC))
  95.                   {
  96.                     printf("Creating message...\n");
  97.                     if (PPCMsg = PPCCreateMessage(ReplyPort, sizeof(TEXT)))
  98.                     {
  99.                       strcpy(Body, TEXT);
  100.                       printf("Sending 1000 SYNCHRON messages with a *Body* and wait for each reply...");
  101.  
  102.                       TimerSetAttr(MyTimerObject,TIMERTAG_START);
  103.                       for (i=0;i<MSGCOUNT;i++)
  104.                       {
  105.                         PPCSendMessage(PPCPort,
  106.                                        PPCMsg,
  107.                                        Body,
  108.                                        sizeof(TEXT),
  109.                                        0x12345678);
  110.                         PPCWaitPort(ReplyPort);
  111.                         PPCGetMessage(ReplyPort);
  112.                       }
  113.                       TimerSetAttr(MyTimerObject,TIMERTAG_STOP);
  114.                       TimerShow(MyTimerObject);
  115.  
  116.                       printf("Waiting for Task Finish Msg...\n");
  117.                       for (;;)
  118.                       {
  119.                         if ((M68kMsg=PPCGetMessage(ReplyPort)) == StartupMsg)
  120.                         {
  121.                           printf("Ahh..the expected Startup=Finish Msg was received.\nNow we can savely free all resources.\n");
  122.                           break;
  123.                         }
  124.                         else
  125.                         {
  126.                           printf("Some non replied Msg 0x%lx was found..wait\n",
  127.                                  M68kMsg);
  128.                           PPCWaitPort(ReplyPort);
  129.                         }
  130.                       }
  131.  
  132.                       printf("Deleting message...\n");
  133.                       PPCDeleteMessage(PPCMsg);
  134.                     }
  135.                     else
  136.                     {
  137.                       Printf("Could not create Msg\n");
  138.                     }
  139.                     PPCFreeVec(Body);
  140.                   }
  141.                   else
  142.                   {
  143.                     Printf("Could not alloc mem for msg body\n");
  144.                   }
  145.                 }
  146.                 else
  147.                 {
  148.                   Printf("Could not find the PPCTask's msgport\n");
  149.                 }
  150.               }
  151.               else
  152.               {
  153.                 Printf("Could not create PPC task\n");
  154.               }
  155.               PPCFreeVec(StartupData);
  156.             }
  157.             else
  158.             {
  159.               Printf("Could not alloc Startup Data\n");
  160.             }
  161.             PPCDeleteMessage(StartupMsg);
  162.           }
  163.           else
  164.           {
  165.             Printf("Could not create Startup message\n");
  166.           }
  167.           PPCDeletePort(ReplyPort);
  168.         }
  169.         else
  170.         {
  171.           Printf("Could not create reply port\n");
  172.         }
  173.         printf("Unloading PPC object\n");
  174.         PPCUnLoadObject(ElfObject);
  175.       }
  176.       else
  177.       {
  178.         Printf("Could not load the elfobject\n");
  179.       }
  180.       TimerDeleteObject(MyTimerObject);
  181.     }
  182.     printf("Closing ppc.library\n");
  183.     CloseLibrary(PPCLibBase);
  184.   }
  185.   else
  186.   {
  187.     Printf("Could not open ppc.library v44+\n");
  188.   }
  189. }
  190.  
  191.